package cc.zhuzhu8.jizhang.controller;

import cc.zhuzhu8.jizhang.entity.Book;
import cc.zhuzhu8.jizhang.entity.BookInfoTotal;
import cc.zhuzhu8.jizhang.entity.DayBookInfo;
import cc.zhuzhu8.jizhang.entity.RetMessage;
import cc.zhuzhu8.jizhang.vo.BookVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/book")
public class BookController {
    @PostMapping("/deleteBook")
    public RetMessage deleteBook(@RequestBody BookVo bookVo) {
        System.out.println(bookVo.getId());
        return RetMessage.ok();
    }
    @PostMapping("/save")
    public RetMessage save(@RequestBody BookVo bookVo) {
        System.out.println(bookVo.getClassId());
        return RetMessage.ok();
    }
    @PostMapping("/getBookList")
    public RetMessage getBookList(@RequestBody String YearMonth) {
        RetMessage retMessage = new RetMessage();
        BookInfoTotal bookInfoTotal = new BookInfoTotal();
        bookInfoTotal.setBalance(100000.00);
        bookInfoTotal.setTotalExpend(40000.00);
        bookInfoTotal.setTotalIncome(500000.00);
        List<DayBookInfo> dayBookInfos = new ArrayList<>();
        DayBookInfo dayBookInfo = new DayBookInfo();
        dayBookInfo.setDay("2021-08-12");
        dayBookInfo.setExpend(4000.00);
        dayBookInfo.setIncome(500.00);


        DayBookInfo dayBookInfo2 = new DayBookInfo();
        dayBookInfo2.setDay("2021-08-13");
        dayBookInfo2.setExpend(4000.00);
        dayBookInfo2.setIncome(500.00);
        dayBookInfo2.setBookList(getBookListStatic());
        dayBookInfos.add(dayBookInfo2);

        DayBookInfo dayBookInfo3 = new DayBookInfo();
        dayBookInfo3.setDay("2021-08-14");
        dayBookInfo3.setExpend(4000.00);
        dayBookInfo3.setIncome(500.00);
        dayBookInfos.add(dayBookInfo3);

        dayBookInfo.setBookList(getBookListStatic());
        dayBookInfo.setDay("2021-08-12");
        dayBookInfos.add(dayBookInfo);
        bookInfoTotal.setDayBookList(dayBookInfos);
        retMessage.setData(bookInfoTotal);
        retMessage.setResult(true);
        return retMessage;
    }

    private List<Book> getBookListStatic() {
        List<Book> list = new ArrayList<>();
        Book book = new Book();
        book.setId(1L);
        book.setAmountOfMoney(100.00);
        book.setBillType(1);
        book.setClassBg("red");
        book.setClassIcon("cuIcon-same");
        book.setRemark("情人节买花");
        book.setClassName("消费");
        list.add(book);
        Book book2 = new Book();
        book2.setId(2L);
        book2.setAmountOfMoney(100.00);
        book2.setBillType(0);
        book2.setClassBg("green");
        book2.setClassIcon("cuIcon-pay");
        book2.setRemark("开发APP收入");
        book2.setClassName("兼职收入");
        list.add(book2);
        return list;

    }
}
